package com.jet.core.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class QuantityUtil {

    public static long parse(BigDecimal quantity) {
        if (quantity == null) {
            return 0;
        }
        return quantity.multiply(BigDecimal.valueOf(1000L)).longValue();
    }

    public static BigDecimal parseBigDecimal(long quantity) {
        return parseBigDecimal(quantity, 2);
    }

    public static BigDecimal parseBigDecimal(long amount, int scale) {
        return BigDecimal.valueOf(amount).divide(BigDecimal.valueOf(1000L), scale, RoundingMode.HALF_UP);
    }
}
